/*
 * @Author: ckk
 * @Date: 2022-08-18 10:39:20
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2023-08-22 16:36:43
 * @Description: your project
 * @version: 1.0
 */
const packageJson = require('./package');
const version = packageJson.version,
  versionStr = version.substring(0, version.indexOf('.', version.indexOf('.') + 1)),
  packageName = packageJson.name.replace(/-/gi, '_'),
  // compressionPlugin = require('compression-webpack-plugin'),
  CopyWebpackPlugin = require('copy-webpack-plugin'),
  path = require('path');

module.exports = {
  devServer: {
    port: 8081,
    disableHostCheck: true,
    // /gw/nbocapi/nboc_outer
    // https://app.zwfw.nmg.gov.cn/
    proxy: {
      '/dgov-authing': {
        target: 'https://app.zwfw.nmg.gov.cn/',
        // target: 'http://192.168.119.10:22100/',
        // target: 'http://vcomyf.bigwoniu.com/',
        changeOrigin: true,
        pathRewrite: {
          '^dgov-authing/': 'dgov-authing/'
        }
      },
      '/qcapp': {
        target: 'https://cs.yjt361.com/',
        // target: 'http://192.168.119.10:22100/',
        // target: 'http://vcomyf.bigwoniu.com/',
        changeOrigin: true,
        pathRewrite: {
          '^qcapp/': 'qcapp/'
        }
      },
      '/gw': {
        target: 'https://cs.yjt361.com/',
        // target: 'http://192.168.119.10:22100/',
        // target: 'http://vcomyf.bigwoniu.com/',
        changeOrigin: true,
        pathRewrite: {
          '^gw/': 'gw/'
        }
      },
      '/ucsui': {
        target: 'https://cs.yjt361.com/',
        // target: 'http://192.168.119.10:22100/',
        // target: 'http://vcomyf.bigwoniu.com/',
        changeOrigin: true,
        pathRewrite: {
          '^ucsui/': 'ucsui/'
        }
      },
      '/ui': {
        target: 'https://cs.yjt361.com/',
        // target: 'http://192.168.119.10:22100/',
        // target: 'http://vcomyf.bigwoniu.com/',
        changeOrigin: true,
        pathRewrite: {
          '^ui/': 'ui/'
        }
      },
      '/operation': {
        target: 'https://cs.czbanbantong.com/',
        // target: 'http://192.168.119.10:22100/',
        // target: 'http://vcomyf.bigwoniu.com/',
        changeOrigin: true,
        pathRewrite: {
          '^operation/': 'operation/'
        }
      },
      '/api': {
        target: 'http://icss.czbanbantong.com',
        // target: 'http://192.168.119.10:22100/',
        // target: 'http://vcomyf.bigwoniu.com/',
        changeOrigin: true,
        pathRewrite: {
          '^api/': 'api/'
        }
      },
      '/ub': {
        target: 'https://cs.yjt361.com/',
        // target: 'http://192.168.119.10:22100/',
        // target: 'http://vcomyf.bigwoniu.com/',
        changeOrigin: true,
        pathRewrite: {
          '^ub/': 'ub/'
        }
      },
      '/national_gw': {
        target: 'https://cs.yjt361.com/',
        // target: 'http://192.168.119.10/',
        //  target: 'http://center.bigwoniu.com/',
        changeOrigin: true,
        pathRewrite: {
          '^national_gw/': 'national_gw/'
        }
      },
      '/isch-c': {
        target: 'http://192.168.164.97:3000/mock/704',
        changeOrigin: true,
        pathRewrite: {
          '^isch-c/': 'isch-c/'
        }
      },
      // appnass
      '/appnass': {
        target: 'https://cs.yjt361.com/',
        changeOrigin: true,
        pathRewrite: {
          '^appnass/': 'appnass/'
        }
      },
      '/protal': {
        target: 'https://cs.yjt361.com/',
        changeOrigin: true,
        pathRewrite: {
          '^protal/': 'protal/'
        }
      },
      '/sso': {
        target: 'https://cs.yjt361.com/',
        changeOrigin: true,
        pathRewrite: {
          '^sso/': 'sso/'
        },
      },
      // h5_release_1
      '/h5_release_1': {
        target: 'https://cs.yjt361.com/',
        changeOrigin: true,
        pathRewrite: {
          '^h5_release_1/': 'h5_release_1/'
        },
      },
      '/national_appnass': {
        target: 'https://cs.yjt361.com/',
        changeOrigin: true,
        pathRewrite: {
          '^national_appnass/': 'national_appnass/'
        },
      },
      '/apptemplate': {
        target: 'https://cs.yjt361.com/',
        changeOrigin: true,
        pathRewrite: {
          '^apptemplate/': 'apptemplate/'
        },
      }
    }
  },
  css: {
    loaderOptions: {
      postcss: {
        plugins: [
          require('postcss-pxtorem')({
            rootValue: 37.5,
            selectorBlackList: [],
            propList: ['*']
          })
        ]
      }
    }
  },
  productionSourceMap: false,
  configureWebpack: (config) => {
    if (process.env.NODE_ENV === 'production') {
      // config.optimization.minimizer[0].options.terserOptions.compress.drop_console = true;
      return {
        plugins: [
          // new compressionPlugin({
          //   test: /\.js$|\.html$|\.css/,
          //   threshold: 10240,
          //   deleteOriginalAssets: false
          // }),
          new CopyWebpackPlugin([{ from: path.resolve(__dirname, './version.md') }])
        ]
      };
    }
    config.externals = { yjUtil: 'yj-utils' };
  },
  publicPath: process.env.PUBLIC_PATH,
  // publicPath:'/rhpt/15f432c028c25000',
  outputDir: `dist/${packageName}_${versionStr}`
};
